@extends('admin/layout.app')

@section('title', '客源列表')

@section('style')
    <link href="//cdn.bootcss.com/flatpickr/2.6.3/flatpickr.min.css" rel="stylesheet">
    <link href="{{ asset('css/admin/tourist.css') }}" rel="stylesheet">
@endsection

@section('content')
    @inject('local,'App\Http\Services\Admin\LocalBladeProvider')

    <div class="search-area">
        <p>
            <input class="form-control tourist-search-text" placeholder="客户ID/姓名/手机号" name="tx" value="{{$query['tx'] or ''}}" style="width: 200px;display:inline-block;">
            <input class="form-control tourist-search-last-man" placeholder="最后跟进人" name="la" value="{{$query['la'] or ''}}" style="width: 200px;display:inline-block;">
            <input type="text" name="start" class="form-control start-time" style="width: 200px;display:inline-block;">
            <input type="text" name="end" class="form-control end-time" style="width: 200px;display:inline-block;">
            <button class="btn btn-default tourist-search">搜索</button>
        </p>
        <p>
            <span>城市：</span>
            @if($city_list)
                @foreach($city_list as $item)
                    <a href="{{ $local->setQuery($current_url,$query,['ct' => $item['name_en']]) }}"
                       data-id="{{$item['city_id']}}"><i
                                class="fa {{ $local->isChecked($query,['ct' => $item['name_en']]) ? 'fa-check-square':'fa-square-o' }}"
                                aria-hidden="true"></i>{{$item['name_cn']}}</a>
                @endforeach
            @endif
        </p>
        <p>
            <span>来源：</span>
            @if($source_list)
                @foreach($source_list as $item)
                    <a href="{{ $local->setQuery($current_url,$query,['sr' => $item['id']]) }}"
                       data-id="{{$item['id']}}"><i
                                class="fa {{ $local->isChecked($query,['sr' => $item['id']]) ? 'fa-check-square':'fa-square-o' }}"
                                aria-hidden="true"></i>{{$item['name']}}</a>
                @endforeach
            @endif
        </p>
        <p>
            <span>状态：</span>
            @if($status_list)
                @foreach($status_list as $item)
                    <a href="{{ $local->setQuery($current_url,$query,['st' => $item['id']]) }}"
                       data-id="{{$item['id']}}"><i
                                class="fa {{ $local->isChecked($query,['st' => $item['id']]) ? 'fa-check-square':'fa-square-o' }}"
                                aria-hidden="true"></i>{{$item['name']}}</a>
                @endforeach
            @endif
        </p>
    </div>
    @if(count($tourists_list))
        <table class="list_tab">
            <thead>
            <tr>
                <th>ID</th>
                <th>城市</th>
                <th>来源</th>
                <th>姓名</th>
                <th>手机号</th>
                <th>状态</th>
                <th>最后跟进时间</th>
                <th>最后跟进人</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($tourists_list as $item)
                <tr class="tourist-line" tid="{{$item['id']}}">
                    <td class="tourist-td-first">
                        @if($item['status'] == 0)
                            <span class="status0-icon"></span>
                        @endif
                        {{ $item['id'] }}
                    </td>
                    <td>{{ $item['city'] }}</td>
                    <td>
                        @if($item['source_id'])
                            @foreach($source_list as $source)
                                @if($source['id'] == $item['source_id'])
                                    {{$source['name']}}
                                @endif
                            @endforeach
                        @endif
                    </td>
                    <td>{{ $item['name'] }}</td>
                    <td>{{ $item['phone'] }}</td>
                    <td>
                        @if($item['status'] >= 0)
                            @foreach($status_list as $status)
                                @if($status['id'] == $item['status'])
                                    {{$status['name']}}
                                @endif
                            @endforeach
                        @endif
                    </td>
                    <td>{{ $item['updated_at'] }}</td>
                    <td>{{ $item['admin_name'] }}</td>
                    <td>
                        <a href="/admin/tourist/{{ $item['id'] }}" class="text-info goto_url" title="编辑客源" data-toggle="tooltip"><i
                                    class="edit-icon" ></i></a>
                        <a href="JavaScript：void(0）" class="text-info" title="拨打电话" data-toggle="tooltip"><i
                                    class="phone-icon" ></i></a>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        {!! $tourists_list->appends($query)->render() !!}
    @else
        @if($query)
        <p>没有查到相关数据，请修改筛选条件</p>
        @endif
    @endif
@endsection

@section('script')
    <script src="//cdn.bootcss.com/flatpickr/2.6.3/flatpickr.min.js"></script>
    <script>
        $(function(){
            $('.start-time').flatpickr({
                defaultDate : '{{ $query['start'] or Carbon\Carbon::now()->subDay() }}',
                enableTime : true,
                enableSeconds : true,
                defaultHour : 0
            });
            $('.end-time').flatpickr({
                defaultDate : '{{ $query['end'] or Carbon\Carbon::now() }}',
                enableTime : true,
                enableSeconds : true,
                defaultHour : 0
            });

            $('.tourist-line').on('click', function () {
                window.location.href = $(this).find('.text-info').attr('href');
            });
        })
    </script>
@endsection

